package com.ultra;

import com.ultra.annotation.CorrectMethod;
import com.ultra.annotation.Validator;
import com.ultra.annotation.ValidatorMethod;
import com.ultra.constraint.Constraint;
import com.ultra.enums.ConstraintTypeEnum;
import com.ultra.template.content.Pairs;
import com.ultra.validator.Active;
import com.ultra.validator.Range;
import java.util.HashMap;
import java.util.Map;

@Validator(count = 1000)
public class AcvApplication {
    @ValidatorMethod
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int key = target - nums[i];
            if (map.containsKey(key)) {
                return new int[]{map.get(key), i};
            } else {
                map.put(nums[i], i);
            }
        }
        return new int[]{-1, -1};
    }
    @CorrectMethod
    public int[] twoSumCorrect(int[] nums, int target) {
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[]{-1, -1};
    }

    public void test1() {
        Map<Pairs, Constraint> constraints = new HashMap<>();

        // 2 <= nums.length <= 10_0000
        Constraint numsLength = new Constraint.Builder(ConstraintTypeEnum.SIZE)
                .range(new Range(2, 10000)).build();

        // 2 <= nums[i] <= 10_0000
        Constraint numsI = new Constraint.Builder(ConstraintTypeEnum.VALUE)
                .range(new Range(-Math.pow(10, 9), Math.pow(10, 9))).build();

        // -10^9 <= target <= 10^9
        Constraint target = new Constraint.Builder(ConstraintTypeEnum.VALUE)
                .range(new Range(-Math.pow(10, 9), Math.pow(10, 9))).build();

        constraints.put(new Pairs(0, 0, 0), numsLength);
        constraints.put(new Pairs(0, 1, 0), numsI);
        constraints.put(new Pairs(1, 0, 0), target);

        new Active().activateValidator(constraints);
    }

    public static void main(String[] args) {
        AcvApplication acv = new AcvApplication();
        acv.test1();
    }
}
